﻿using System.Collections.Generic;
using Ninject;
using RentalOfCars.Domain.Entities;
using RentalOfCars.Server.Domain.ClientServerInterface;

namespace RentalOfCars.Client.Presentation
{
    public class AddCarWindowPresenter
    {
        private readonly IDbAccessSession _session;
        private readonly IAddCarWindowView _view;
        private readonly IKernel _kernel;
        private IList<IBrand> _brands;

        public AddCarWindowPresenter(IAddCarWindowView view, IDbAccessSession session, IKernel kernel)
        {
            _view = view;
            _kernel = kernel;
            _session = session;

            _view.OnOk = OnOk;

        }

        private void UpdateAvailableBrands()
        {
            _brands = _session.GetBrands();
            var ds = new string[_brands.Count];
            for (int i = 0; i < _brands.Count; i++)
            {
                ds[i] = _brands[i].Name;
            }

            _view.AvailableFeatures = ds;
        }


        private void OnOk()
        {
            string name = _view.Name;
            string brand = _view.Brand;
            int cost = _view.Cost;
            int price = _view.Price;
            IDictionary<string, string> features = _view.Features;

            var car = new Infrastructure.Entities.Car(0, name, brand, cost, price, features);
            _session.AddCar(car);

            _view.CloseWindow();
        }
    }
}
